package com.zz.admin.mainTableManagement.controller;

import com.zz.admin.mainTableManagement.dto.MainTableDto;
import com.zz.admin.mainTableManagement.service.MainTableService;
import java.util.List;
import java.util.Map;

import com.zz.common.base.dto.PageListResultDto;
import com.zz.common.base.dto.ResponseDTO;
import com.zz.common.base.dto.ResultDto;
import com.zz.common.constants.ApiConstants;

import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 主 服务接口类
 * @author zl
 * @since 2025-11-18 19:08:00
 */
@Api(tags = "主服务接口类")
@RestController
@RequestMapping("main-table-management/v1.0/main-table")
public class MainTableController {

    @Resource
    private MainTableService mainTableService;

    @RequestMapping(value = "/query-with-page", method = RequestMethod.POST)
    @ApiOperation(value = "主-分页查询", notes = "传入分页信息")
    public PageListResultDto<MainTableDto> queryWithPage(@RequestBody MainTableDto mainTableDto) {
        PageListResultDto<MainTableDto> res;
        res = mainTableService.queryWithPage(mainTableDto, mainTableDto.getQueryParam());
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    
    @RequestMapping(value = "/query-with-no-page", method = RequestMethod.POST)
    @ApiOperation(value = "主-不分页查询", notes = "传入查询条件信息")
    public ResponseDTO<List<MainTableDto>> queryWithNoPage(@RequestBody MainTableDto mainTableDto) {
        ResponseDTO<List<MainTableDto>> res = new ResponseDTO<>();
        res.setData(mainTableService.queryWithNoPage(mainTableDto));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }
    
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "主-查询ById", notes = "传入id")
    public ResponseDTO<MainTableDto> queryById(@PathVariable("id") String id) {
        ResponseDTO<MainTableDto> res = new ResponseDTO<>();
        MainTableDto result = mainTableService.queryById(id);
        res.setData(result);
        return res;
    }

    @RequestMapping(value = "/query-by-ids", method = RequestMethod.POST)
    @ApiOperation(value = "主-查询ByIds", notes = "传入ids")
    public ResponseDTO<List<MainTableDto>> queryByIds(@RequestBody List<String> ids) {
        ResponseDTO<List<MainTableDto>> res = new ResponseDTO<>();
        res.setData(mainTableService.queryByIds(ids));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "主-创建", notes = "创建")
    public ResultDto save(@RequestBody MainTableDto mainTableDto) {
        ResultDto res = new ResultDto();
        mainTableService.save(mainTableDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save-batch", method = RequestMethod.POST)
    @ApiOperation(value = "主-创建", notes = "创建")
    public ResultDto saveBatch(@RequestBody List<MainTableDto> mainTableDtos) {
        ResultDto res = new ResultDto();
        mainTableService.saveBatch(mainTableDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    @ApiOperation(value = "主-修改", notes = "修改")
    public ResultDto modify(@RequestBody MainTableDto mainTableDto) {
        ResultDto res = new ResultDto();
        mainTableService.modify(mainTableDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify-batch", method = RequestMethod.POST)
    @ApiOperation(value = "主-修改", notes = "修改")
    public ResultDto modifyBatch(@RequestBody List<MainTableDto> mainTableDtos) {
        ResultDto res = new ResultDto();
        mainTableService.modifyBatch(mainTableDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "主-删除ById", notes = "传入id")
    public ResultDto delete(@PathVariable("id")  String id) {
        ResultDto res = new ResultDto();
        mainTableService.delete(id);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete-batch", method = RequestMethod.POST)
    @ApiOperation(value = "主-批量删除", notes = "传入id")
    public ResultDto deleteBatch(@RequestBody List<String> ids) {
        ResultDto res = new ResultDto();
        mainTableService.deleteBatch(ids);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

}